/**
 * File Name	: CipherUtil.java
 * Author		: Administrator:Adelwin
 * Create Date	: Mar 29, 2006:11:34:55 PM
 *
 * Copyright (c) 2006 Adelwin. All Rights Reserved. <BR>
 * <BR>
 * This software contains confidential and proprietary information of
 * Adelwin. ("Confidential Information").<BR>
 * <BR>
 * Such Confidential Information shall not be disclosed and it shall
 * only be used in accordance with the terms of the license agreement
 * entered into with Solveware Independent; other than in accordance with the written
 * permission of Solveware Independent. <BR>
 *
 *
 */

package com.uobgroup.cmt.base.util;

import com.uobgroup.cmt.base.exception.CipherException;

public class CipherUtil {

	private static final String	DEFAULT_METHOD	= "MD5";

	public static final String encrypt(String method, String input, String key) throws CipherException {
		//		return input;
		CipherWrapper cipherWrapper = CipherWrapper.getCipher(method);
		byte[] encrypted = cipherWrapper.encrypt(input.getBytes(), key.getBytes());
		return new String(encrypted);
	}

	public static final String decrypt(String method, String input, String key) throws CipherException {
		CipherWrapper cipherWrapper = CipherWrapper.getCipher(method);
		byte[] decrypted = cipherWrapper.decrypt(input.getBytes(), key.getBytes());
		return new String(decrypted);
	}

	/**
	 * the following two methods should be implemented to provide functionality to encrypt and decrypt simple algorithm used on client side with javascript
	 * @throws CipherException 
	 */
	public static final String encrypt(String input, String key) throws CipherException {
		return encrypt(DEFAULT_METHOD, input, key);
	}

	public static final String decrypt(String input, String key) throws CipherException {
		return decrypt(DEFAULT_METHOD, input, key);
	}
}
